package com.learning.JavaSE.workExercise.module4.Task1;
/**
 *编写一个员工类   (1)属性: 姓名,年龄       如果年龄小于18龄大于150抛出年龄异常       如果姓名为null或者""抛出空异常
 */
public class Employee {
    private String name;
    private int age;
    public Employee() {
    }

    public Employee(String name, int age) {
        setName(name);
        setAge(age);
    }

    public String getName() {
        return name;
    }

    //如果姓名为null或者""抛出空异常
    public void setName(String name) {
        if(name != null && name != "") {
            this.name = name;
        }else {
            System.out.println("姓名不合理哦！！！");
            try{
                throw new NameException("姓名不合理哦！！！");
            }catch (NameException e1){
                e1.printStackTrace();
            }
        }
    }

    public int getAge() {
        return age;
    }
    //如果年龄小于18龄大于150抛出年龄异常
    public void setAge(int age) {
        if (age > 18 && age < 150) {
            this.age = age;
        } else {
            System.out.println("年龄不合理哦！！！");
            try {
                throw new AgeException("年龄不合理哦！！！");
            } catch (AgeException e2) {
                e2.printStackTrace();
            }
        }
    }




}
